﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class RollList
{
    //  private int itemNum;

 

    private GameObject _parentObj;

    public RollList()
    {

    }

    public delegate void onDragHandler(object obj);

    // public event onDragHandler onDragEvent;

    private Dictionary<string, ItemBase> itemDic = new Dictionary<string,ItemBase>();

    private int itemNum;


    public void initRollItem(GameObject parentObj, List<string> itemList)
    {

        _parentObj = parentObj;

        for (int i = 0; i < itemList.Count; i++)
        {
            ItemBase item = new ItemBase();

            item.initItemBase(itemList[i]);

            itemDic.Add(itemList[i], item);

            /// 设置位置
            int center = 0;
         
            /// item 初始定位。默认x偏移为350
          /*  if (i == 0)
            {
                item.currentPosition = new Vector3(0, 0, 0);
                item.setItemDepth (itemList.Count);
            }
            else
            {
                item.setItemDepth((itemList.Count- 1)/2);
                if (i / 2 == 0)
                    item.currentPosition = new Vector3((-1 * (i + 1) / 2) * 350, 0, 40);                   
                else
                    item.currentPosition = new Vector3((i / 2) * 350, 0, 0);
            }

            SparkExtensions.setParent(item.item, _parentObj, item.currentPosition.x, item.currentPosition.y);*/
        }

        
        /*foreach (KeyValuePair<string, ItemBase> item in itemDic)
        {
              item.Value.nextPosition =       
        }*/

        /* ItemBase high = new ItemBase();
         high.initItemBase("btnHighHouse");

         ItemBase middle = new ItemBase();
         middle.initItemBase("btnMiddleHouse");

         ItemBase low = new ItemBase();
         low.initItemBase("btnLowHouse");

        // for 
        // itemDic.Add
        
         SparkExtensions.setParent(high.item, _parentObj, 0f, 0f);
         SparkExtensions.setParent(middle.item, _parentObj, 350f, 0f);
         SparkExtensions.setParent(low.item, _parentObj, -350f, 0f);

       /*  onDragEvent += high.onDrag;
         onDragEvent += middle.onDrag;
         onDragEvent += low.onDrag;
         */
        /*UIEventListener.Get(parentObj).onDrag = OnDrag;

        UIEventListener.Get(high.item).onClick = onClick;
        UIEventListener.Get(middle.item).onClick = onClick;
        UIEventListener.Get(low.item).onClick = onClick;

        UIEventListener.Get(high.item).onDrag = OnDrag;
        UIEventListener.Get(middle.item).onDrag = OnDrag;
        UIEventListener.Get(low.item).onDrag = OnDrag;*/
    }

    void OnDrag(GameObject button, Vector2 delta)
    {
        Debug.Log("GameObject " + button.name);
        TweenPosition.Begin(button, 2, new Vector3(button.transform.position.x + 140, button.transform.position.y + 140, 0));
        TweenScale.Begin(button, 2, new Vector3(0.8f, 0.8f, 1f)); ;

        //  onDragEvent(_parentObj);
    }

    void onClick(GameObject bt)
    {
        Debug.Log("click");
    }

}
